import path from 'path';
import express from 'express';
import logger from 'morgan';
import compression from 'compression';
import helmet from 'helmet';
import hpp from 'hpp';
import favicon from 'serve-favicon';
import chalk from 'chalk';


import devServer from './devServer';
import ssr from './ssr';
import config from '../config';
import { error } from 'console';

const app = express();

app.use(helmet({ contentSecurityPolicy: false }));

app.use(hpp());

app.use(compression());

app.use(logger('dev', { skip: (_, res) => res.statusCode < 400 }));
app.use(favicon(path.resolve(process.cwd(), 'public/logo.png')));
app.use(express.static(path.resolve(process.cwd(), 'public')));

if (__DEV__) devServer(app);

app.get('*', ssr);

app.listen(config.PORT, config.HOST, (error) => {
    if (error) console.error(chalk.red(`===> OMG!!! ${error}`))
})